<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%! String gr; %>
<style type="text/css">
#output tr td{

}
</style>
<script type="text/javascript" src="./js/jquery-1.10.2.js"></script>
<script type="text/javascript">
var save_gubun=0; // 신규입력인지 수정인지 구분 : 0: 신규/ 1: 수정
var oldhakbun = ''; // 수정되기 전의 학번 임시 저장

function init(){
	hakbun.value='';
	name1.value='';
	address.value='';
	passwd.value='';
	email.value='';
	tel.value='';
	jumin1.value='';
	jumin2.value='';
	
	$('input:radio[name=gender]:input[value=M]').prop('checked',true);
}

function save(){
	/* var hakbun = $('#hakbun').val(); */
	var hakbun = '${userId}';
	var name = $('#name1').val();
	var address = $('#address').val();
	var gwa_code = $('#gwa_code').val();
	var passwd = $('#passwd').val();
	var email = $('#email').val();
	var tel = $('#tel').val();
	var jumin1 = $('#jumin1').val();
	var jumin2 = $('#jumin2').val();
	var gender = $("input[name='gender']:checked").val();
	
	var data={"hakbun":hakbun, "name":name, "address":address, "gwa_code":gwa_code,"passwd":passwd,
			"email":email,"tel":tel,"jumin1":jumin1,"jumin2":jumin2,"gender":gender};
	
	$.ajax({
		type:"post",
		data:data,
		url:"modifyStudent.do",
		dataType:"json",
		success:function(data1){
			$("#output").empty();
			var head = "";
					
			$("#output").append(head);
			/* $('#listTable').html(''); */
			
			$(data1).each(function(index,item){
				output+="<tr>";
				output+="<td>" +"이름" + "</td>";
				output+="<td>" +item.name +"</td>";
				output+="</tr>";
				output+="<tr>";
				output+="<td>" +"주소" + "</td>";
				output+="<td>"+ item.address + "</td>";
				output+="</tr>";
				output+="<tr>";
				output+="<td>" +"비밀번호" + "</td>";
				output+="<td>"+ item.passwd + "</td>";				
				output+="</tr>";
				output+="<tr>";
				output+="<td>" +"이메일" + "</td>";
				output+="<td>"+ item.email + "</td>";				
				output+="</tr>";
				output+="<tr>";
				output+="<td>" +"전화" + "</td>";
				output+="<td>"+ item.tel + "</td>";				
				output+="</tr>";
				output+="<tr>";
				output+="<td>" +"주민번호" + "</td>";
				output+="<td>"+item.jumin1 +"-"+item.jumin2 + "</td>";				
				output+="</tr>";
				output+="<tr>";
				output+="<td>" +"성별" + "</td>";
				output+="<td>"+item.gender + "</td>";				
				output+="</tr>";
							
				$("#output").append(output);
				output = '';
			});
		}
	
	});
	save_gubun = 0; //업데이트 후 다시 save_gubun = 0으로 셋팅
	init(); 
	
	alert('저장이 되었습니다.');
}

	

	
function modify(){
	 location.href = "personalMng.do";
}
function finish(){
	 location.href = "staffMain.do";
}
</script>
<body>
<div class="command">
<table class="table2">
	<tr>
		<th><spring:message code="student.form.hakbun"/></th>
		<td>${studentCommand.hakbun }</td>
		<td><input type="hidden" id="hakbun" value="${studentCommand.hakbun }"></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.name"/></th>
		<td><input type="text" id="name1"  value="${studentCommand.name }"/></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.address"/></th>
		<td><input type="text" id="address" style="width:300px;" value="${studentCommand.address }"/></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.gwa_code"/></th>
		<td>${gwaName }</td>
		<td><input type="hidden" id="gwa_code" value="${studentCommand.gwa_code }"></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.passwd"/></th>
		<td><input type="text" id="passwd"  value="${studentCommand.passwd }"/></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.email"/></th>
		<td><input type="text" id="email"  value="${studentCommand.email }"/></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.tel"/></th>
		<td><input type="text" id="tel"  value="${studentCommand.tel }"/></td>
	</tr>
	<tr>
		<th><spring:message code="student.form.jumin"/></th>
		<td><input type="text" id="jumin1"  value="${studentCommand.jumin1 }"/>-<input type="text" id="jumin2"  value="${studentCommand.jumin2 }"/></td>
		
	</tr>
	<tr>
		<th><spring:message code="student.form.gender"/></th>
		<td><c:choose>
			<c:when test="${studentCommand.gender=='M'}"><input name="gender" type="radio" value='M' checked/>남성<input name="gender" type="radio" value='F'>여성<br></c:when>
			<c:otherwise><input name="gender" type="radio" value='M'/>남성<input name="gender" type="radio" value='F' checked>여성<br></c:otherwise>
	 		</c:choose></td>
	</tr>
	<tr><td colspan="2">
	<input type="button" id="btnMf" value="수정"onclick="modify()" /> 
	<input type="button" id="btnSave" value="저장" onclick="save()" />
	<input type="button" id="btnExit" value="종료" onclick="finish()" />
	</td></tr>
</table>

</div>

	<table id="output" border=0 ></table>

</body>
</html>
